﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

namespace Chenxin.Lib.House.BLL
{
    public class House_BaseInfo
    {
        #region  公有方法

        //*******************************************
        //功能概要       ：添加房源信息
        //参数説明       ：
        //返回值説明     ：
        //功能詳細       ：添加房源信息
        //作成者         ：姚志强
        //作成日         ：2010-03-01
        //修改者         ：
        //修改日         ：
        //*******************************************
        public static string AddHouseInfo(Chenxin.Lib.House.Entity.House_BaseInfo houseBaseInfo, Chenxin.Lib.House.Entity.Customer_BaseInfo customerBaseInfo)
        {
            try
            {
                if (!ValidateHouseKey(Convert.ToString(houseBaseInfo.CommunityId), Convert.ToString(houseBaseInfo.BuildingId), Convert.ToString(houseBaseInfo.Room)))
                {
                    return  "{" + string.Format("result:'false',msg:'{0}'", "唯一性验证失败，该房源已存在！") + "}";
                }

                //设置房源编号
                houseBaseInfo.HouseCode = GetHouseCode(houseBaseInfo.AddPersonId);
                //插入房源的基本信息
                Chenxin.Lib.House.DAL.House_BaseInfo.Add(houseBaseInfo);

                //客户编号
                //customerBaseInfo.CustomerCode = "001-001-001-001";
                //插入对应的客源的基本信息
                Chenxin.Lib.House.BLL.Custom_Info.AddCustomBaseInfo(customerBaseInfo);

                ////插入系统操作日志
                //string oprType = "添加房源";
                //string oprContext = "添加了一条房源记录:" + houseBaseInfo.Community + houseBaseInfo.BuildingName + houseBaseInfo.Room;

                //AddHouseUserLogs(houseBaseInfo, oprType, oprContext);

                return "{" + string.Format("result:'true',msg:'{0}'", houseBaseInfo.HouseCode) + "}";
            }
            catch (Exception ex)
            {
                return "{" + string.Format("result:'false',msg:'{0}'", ex.Message) + "}";
            }
        }

        /// <summary>
        /// 更新房源信息
        /// </summary>
        /// <param name="model"></param>
        public static void UpdateHouse(Chenxin.Lib.House.Entity.House_BaseInfo model, Chenxin.Lib.House.Entity.House_TraceInfo house_TraceInfo)
        {
            Chenxin.Lib.House.Entity.House_BaseInfo oldModel = Chenxin.Lib.House.DAL.House_BaseInfo.GetModel(model.HouseId);

            if (oldModel != null)
            {
                Chenxin.Lib.House.DAL.House_BaseInfo.Update(model);
                string updateContext = GetChangeLog(oldModel, model, house_TraceInfo);

                if (!string.IsNullOrEmpty(updateContext))
                {
                    //写入房源跟单
                    AddTraceInfo(model, updateContext, house_TraceInfo);

                    //添加日志
                    Chenxin.Lib.House.Entity.House_UserLogs userLogs = new Chenxin.Lib.House.Entity.House_UserLogs();
                    userLogs.RecordId = Guid.NewGuid();
                    userLogs.UserId = house_TraceInfo.TractorId;
                    userLogs.UserName = house_TraceInfo.Tractor;
                    userLogs.DepartId = house_TraceInfo.DepartId;
                    userLogs.DepartName = house_TraceInfo.Depart;
                    userLogs.OperationContext = house_TraceInfo.Tractor + "更新了一个房源:" + model.Community + model.BuildingName + model.Room;
                    userLogs.OprType = "更新房源";
                    userLogs.Addtime = DateTime.Now;
                    userLogs.Id = house_TraceInfo.TractorId;
                    Chenxin.Lib.House.DAL.House_UserLogs.Add(userLogs);
                    //AddHouseUserLogs(house_TraceInfo, oprType, updateCustomerDemandInfoContext, oldCustomBaseInfo.CustomerId);

                    //插入消息通知
                    string noticeTitle = "房源:" + model.Community + model.BuildingName + model.Room + "信息被修改";
                    AddNotice(model, noticeTitle, updateContext);
                }
            }
        }

        #region 获取部分变量的文字描述,私有方法，熊世宏 2010-04-28
        /// <summary>
        /// 获取交易类型文字描述
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private static string GetBusinessKind(int? value)
        {
            string _val = "";
            switch (value)
            {
                case 10:
                    _val= "出租";
                    break;
                case 20:
                    _val = "出售";
                    break;
                case 30:
                    _val = "租售";
                    break;
            }
            return _val;
        }

        /// <summary>
        /// 获取状态文字描述
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private static string GetStatus(int? value)
        {
            string _val = "";
            switch (value)
            {
                case 10:
                    _val = "有效";
                    break;
                case 20:
                    _val = "暂缓";
                    break;
                case -1:
                    _val = "无效";
                    break;
                case 30:
                    _val = "暂缓";
                    break;
            }
            return _val;
        }

        /// <summary>
        /// 获取真假的有无文字描述
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private static string GetHaving(bool value)
        {
            if (value)
            {
                return "有";
            }
            return "无";
        }
        #endregion 

        /// <summary>
        /// 获取字段更改日志
        /// </summary>
        /// <param name="oldModel">原Model</param>
        /// <param name="newModel">新Model</param>
        /// <returns></returns>
        public static string GetChangeLog(Chenxin.Lib.House.Entity.House_BaseInfo oldModel, Chenxin.Lib.House.Entity.House_BaseInfo newModel, Chenxin.Lib.House.Entity.House_TraceInfo house_TraceInfo)
        {

            StringBuilder updateContext = new StringBuilder();
            StringBuilder bakColSql = new StringBuilder();

            string strSql = "INSERT INTO House_BaseInfo_BakCol ";
            strSql += "([RecordId],[HouseId],[ColumnName],[ColumnDesc],[OldValue],[NewValue],[ChangeDesc],";
            strSql += "[CompanyId],[CompanyName],[OperatorId],[Operator],[Adddate])VALUES";
            strSql += "('{0}','" + oldModel.HouseId + "',";
            strSql += "'{1}','{2}','{3}','{4}','{5}',";
            //strSql += "'" + newModel.CompanyId + "','" + newModel.CompanyName + "','" + newModel.OprPersonId + "','" + newModel.OprPerson + "','" + DateTime.Now + "') ";
            strSql += "'" + house_TraceInfo.CompanyId + "','" + house_TraceInfo.CompanyName + "','" + house_TraceInfo.TractorId + "','" + house_TraceInfo.Tractor + "','" + DateTime.Now + "') ";

            string strChangeDesc="{0}由：{1}修改为：{2}";

            #region 获取改变日志
            #region 区域
            //区域
            if (oldModel.Region != newModel.Region)
            {
                string changeDesc = string.Format(strChangeDesc, "区域", oldModel.Region, newModel.Region);
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql,Guid.NewGuid(), "Region", "区域", oldModel.Region, newModel.Region, changeDesc);
            }
            //装修情况
            if (oldModel.Fitment != newModel.Fitment)
            {
                string changeDesc = string.Format(strChangeDesc, "装修情况", oldModel.Fitment, newModel.Fitment);
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "Fitment", "装修情况", oldModel.Fitment, newModel.Fitment, changeDesc);
            }
            //朝向
            if (oldModel.Direction != newModel.Direction)
            {
                string changeDesc = string.Format(strChangeDesc, "朝向", oldModel.Direction, newModel.Direction);
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "Direction", "朝向", oldModel.Direction, newModel.Direction, changeDesc);
            }
            #endregion

            #region 板块
            //板块
            if (oldModel.Block != newModel.Block)
            {
                string changeDesc = string.Format(strChangeDesc, "板块", oldModel.Block, newModel.Block);
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "Block", "板块", oldModel.Block, newModel.Block, changeDesc);
            }
            #endregion
            
            #region 交易类型
            //交易类型
            if (oldModel.BusinessKind != newModel.BusinessKind)
            {
                string changeDesc = string.Format(strChangeDesc, "交易类型", GetBusinessKind(oldModel.BusinessKind), GetBusinessKind(newModel.BusinessKind));
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "BusinessKind", "交易类型", oldModel.BusinessKind, newModel.BusinessKind, changeDesc);
            }
            #endregion

            #region 状态
            //状态
            if (oldModel.Status != newModel.Status)
            {
                string changeDesc = string.Format(strChangeDesc, "状态", GetStatus(oldModel.Status), GetStatus(newModel.Status));
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "Status", "状态", oldModel.Status, newModel.Status, changeDesc);
            }
            #endregion

            #region 用途
            //用途
            if (oldModel.HouseUse != newModel.HouseUse)
            {
                string changeDesc = string.Format(strChangeDesc, "用途", oldModel.HouseUse, newModel.HouseUse);
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "HouseUse", "用途", oldModel.HouseUse, newModel.HouseUse, changeDesc);
            }
            #endregion

            #region 类型
            //类型
            if (oldModel.BuildingType != newModel.BuildingType)
            {
                string changeDesc = string.Format(strChangeDesc, "类型", oldModel.BuildingType, newModel.BuildingType);
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "BuildingType", "类型", oldModel.BuildingType, newModel.BuildingType, changeDesc);
            }
            #endregion

            #region 出售总价
            //出售总价
            if (oldModel.SalePrice_T != newModel.SalePrice_T)
            {
                string changeDesc = string.Format(strChangeDesc, "出售总价", oldModel.SalePrice_T, newModel.SalePrice_T);
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "SalePrice_T", "出售总价", oldModel.SalePrice_T, newModel.SalePrice_T, changeDesc);
            }
            #endregion

            #region 出售底价
            //出售底价
            if (oldModel.SalePrice_R != newModel.SalePrice_R)
            {
                string changeDesc = string.Format(strChangeDesc, "出售底价", oldModel.SalePrice_R, newModel.SalePrice_R);
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "SalePrice_R", "出售底价", oldModel.SalePrice_R, newModel.SalePrice_R, changeDesc);
            }
            #endregion

            #region 出租总价
            //出租总价
            if (oldModel.RentPrice != newModel.RentPrice)
            {
                string changeDesc = string.Format(strChangeDesc, "出租总价", oldModel.RentPrice, newModel.RentPrice);
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "RentPrice", "出租总价", oldModel.RentPrice, newModel.RentPrice, changeDesc);
            }
            #endregion

            #region 出租底价
            //出租底价
            if (oldModel.RentPrice_R != newModel.RentPrice_R)
            {
                string changeDesc = string.Format(strChangeDesc, "出租底价", oldModel.RentPrice_R, newModel.RentPrice_R);
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "RentPrice_R", "出租底价", oldModel.RentPrice_R, newModel.RentPrice_R, changeDesc);
            }
            #endregion


            #region 建筑面积
            //建筑面积
            if (oldModel.BuildingArea != newModel.BuildingArea)
            {
                string changeDesc = string.Format(strChangeDesc, "建筑面积", oldModel.BuildingArea, newModel.BuildingArea);
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "BuildingArea", "建筑面积", oldModel.BuildingArea, newModel.BuildingArea, changeDesc);
            }
            #endregion

            #region 房型-室
            //房型-室
            if (oldModel.Model_Room != newModel.Model_Room)
            {
                string changeDesc = string.Format(strChangeDesc, "房型-室", oldModel.Model_Room, newModel.Model_Room);
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "Model_Room", "房型-室", oldModel.Model_Room, newModel.Model_Room, changeDesc);
            }
            #endregion

            #region 房型-厅
            //房型-厅
            if (oldModel.Model_Hall != newModel.Model_Hall)
            {
                string changeDesc = string.Format(strChangeDesc, "房型-厅", oldModel.Model_Hall, newModel.Model_Hall);
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "Model_Hall", "房型-厅", oldModel.Model_Hall, newModel.Model_Hall, changeDesc);
            }
            #endregion

            #region 房型-卫
            //房型-卫
            if (oldModel.Model_Toilet != newModel.Model_Toilet)
            {
                string changeDesc = string.Format(strChangeDesc, "房型-卫", oldModel.Model_Toilet, newModel.Model_Toilet);
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "Model_Toilet", "房型-卫", oldModel.Model_Toilet, newModel.Model_Toilet, changeDesc);
            }
            #endregion

            #region 阳台
            //阳台
            if (oldModel.Model_Balcony != newModel.Model_Balcony)
            {
                string changeDesc = string.Format(strChangeDesc, "阳台", oldModel.Model_Balcony, newModel.Model_Balcony);
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "Model_Balcony", "阳台", oldModel.Model_Balcony, newModel.Model_Balcony, changeDesc);
            }
            #endregion

            #region 所在楼层
            //所在楼层
            if (oldModel.Cur_Floor != newModel.Cur_Floor)
            {
                string changeDesc = string.Format(strChangeDesc, "所在楼层", oldModel.Cur_Floor, newModel.Cur_Floor);
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "Cur_Floor", "所在楼层", oldModel.Cur_Floor, newModel.Cur_Floor, changeDesc);
            }
            #endregion

            #region 总楼层
            //总楼层
            if (oldModel.Total_Floor != newModel.Total_Floor)
            {
                string changeDesc = string.Format(strChangeDesc, "总楼层", oldModel.Total_Floor, newModel.Total_Floor);
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "Total_Floor", "总楼层", oldModel.Total_Floor, newModel.Total_Floor, changeDesc);
            }
            #endregion

            #region 现状
            //现状
            if (oldModel.Actuality != newModel.Actuality)
            {
                string changeDesc = string.Format(strChangeDesc, "现状", oldModel.Actuality, newModel.Actuality);
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "Actuality", "现状", oldModel.Actuality, newModel.Actuality, changeDesc);
            }
            #endregion

            #region 产权情况
            //产权情况
            if (oldModel.Property != newModel.Property)
            {
                string changeDesc = string.Format(strChangeDesc, "产权情况", oldModel.Property, newModel.Property);
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "Property", "产权情况", oldModel.Property, newModel.Property, changeDesc);
            }
            #endregion

            #region 竣工年份
            //竣工年份
            if (oldModel.CompleteYear != newModel.CompleteYear)
            {
                string changeDesc = string.Format(strChangeDesc, "竣工年份", oldModel.CompleteYear, newModel.CompleteYear);
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "CompleteYear", "竣工年份", oldModel.CompleteYear, newModel.CompleteYear, changeDesc);
            }
            #endregion

            #region 租约
            //租约
            if (oldModel.HavRentContract != newModel.HavRentContract)
            {
                string changeDesc = string.Format(strChangeDesc, "租约", GetHaving(oldModel.HavRentContract), GetHaving(newModel.HavRentContract));
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "HavRentContract", "租约", oldModel.HavRentContract, newModel.HavRentContract, changeDesc);
            }
            #endregion


            #region 钥匙
            //钥匙
            if (oldModel.IsHavekey != newModel.IsHavekey)
            {
                string changeDesc = string.Format(strChangeDesc, "钥匙", GetHaving(oldModel.IsHavekey), GetHaving(newModel.IsHavekey));
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "IsHavekey", "钥匙", oldModel.IsHavekey, newModel.IsHavekey, changeDesc);
            }
            #endregion

            #region 来源
            //来源
            if (oldModel.InfoSource != newModel.InfoSource)
            {
                string changeDesc = string.Format(strChangeDesc, "来源", oldModel.InfoSource, newModel.InfoSource);
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "InfoSource", "来源", oldModel.InfoSource, newModel.InfoSource, changeDesc);
            }
            #endregion

            #region 房源配置
            //房源配置
            if (oldModel.BaseEquip != newModel.BaseEquip)
            {
                string changeDesc = string.Format(strChangeDesc, "房源配置", oldModel.BaseEquip, newModel.BaseEquip);
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "BaseEquip", "房源配置", oldModel.BaseEquip, newModel.BaseEquip, changeDesc);
            }
            #endregion

            #region 备注
            //备注
            if (oldModel.Remarks != newModel.Remarks)
            {
                string changeDesc = string.Format(strChangeDesc, "备注", oldModel.Remarks, newModel.Remarks);
                updateContext.Append(changeDesc);
                bakColSql.AppendFormat(strSql, Guid.NewGuid(), "Remarks", "备注", oldModel.Remarks, newModel.Remarks, changeDesc);
            }
            #endregion
            #endregion

            if (bakColSql.Length > 0)
            {
                //更新数据库的备份表
                Chenxin.Lib.House.DAL.House_BaseInfo_BakCol.AddBakColList(bakColSql.ToString());
            }

            return updateContext.ToString();
        }


        /// <summary>
        /// 插入房源信息，同时插入客源记录
        /// </summary>
        /// <param name="houseModel">房源实体</param>
        /// <param name="customerModel">客源实体</param>
        /// <returns></returns>
        public static bool Add(Chenxin.Lib.House.Entity.House_BaseInfo houseModel, Chenxin.Lib.House.Entity.Customer_BaseInfo customerModel)
        {
            if (!ValidateHouseKey(Convert.ToString(houseModel.CommunityId), Convert.ToString(houseModel.BuildingId), Convert.ToString(houseModel.Room)))
            {
                return false;
            }

            //客户编号
            //customerBaseInfo.CustomerCode = "001-001-001-001";
            //插入对应的客源的基本信息
            Chenxin.Lib.House.BLL.Custom_Info.AddCustomBaseInfo(customerModel);

            houseModel.CustomerId = customerModel.CustomerId;
            //设置房源编号
            houseModel.HouseCode = GetHouseCode(houseModel.AddPersonId);
            //插入房源的基本信息
            Chenxin.Lib.House.DAL.House_BaseInfo.Add(houseModel);


            ////插入系统操作日志
            //string oprType = "添加房源";
            //string oprContext = "添加了一条房源记录:" + houseModel.Community + houseModel.BuildingName + houseModel.Room;

            //AddHouseUserLogs(houseModel, oprType, oprContext);
            return true;
        }


        //*******************************************
        //功能概要       ：修改房源信息
        //参数説明       ：
        //返回值説明     ：
        //功能詳細       ：修改房源信息
        //作成者         ：姚志强
        //作成日         ：2010-03-01
        //修改者         ：
        //修改日         ：
        //*******************************************
        public static string UpdateHouseInfo(Chenxin.Lib.House.Entity.House_BaseInfo houseBaseInfo) 
        {
            /*
            try
            {
                //取得更新之前的房源信息
                Chenxin.Lib.House.Entity.House_BaseInfo oldHouseInfo = Chenxin.Lib.House.DAL.House_BaseInfo.GetModel(houseBaseInfo.HouseId);

                //修改房源信息
                Chenxin.Lib.House.DAL.House_BaseInfo.Update(houseBaseInfo);

                //写入房源更改记录
                string updateContext = AddHouseInfoBak(houseBaseInfo, oldHouseInfo);

                //写入房源跟单
                AddTraceInfo(houseBaseInfo, updateContext);

                //插入消息通知
                string noticeTitle = "房源:" + houseBaseInfo.Community + houseBaseInfo.BuildingName + houseBaseInfo.Room + "信息被修改";
                AddNotice(houseBaseInfo, noticeTitle, updateContext);

                //插入系统操作日志
                string oprType = "更新房源";

                AddHouseUserLogs(houseBaseInfo, oprType, updateContext);

                return "{" + string.Format("result:'true',msg:'{0}'", "保存成功") + "}";
            }
            catch (Exception ex) {
                return "{" + string.Format("result:'false',msg:'{0}'", ex.Message) + "}";
            }
             * */
            return "";
        }

        //*******************************************
        //功能概要       ：添加房源收藏
        //参数説明       ：
        //返回值説明     ：
        //功能詳細       ：添加房源收藏
        //作成者         ：姚志强
        //作成日         ：2010-03-01
        //修改者         ：
        //修改日         ：
        //*******************************************
        public static string AddFavorsInfo(Chenxin.Lib.House.Entity.Personal_FavorsInfo favorsInfo) {
            try
            {
                //添加房源收藏
                Chenxin.Lib.House.DAL.Personal_FavorsInfo.Add(favorsInfo);

                return "{" + string.Format("result:'true',msg:'{0}'", "添加成功") + "}";
            }
            catch (Exception ex) {
                return "{" + string.Format("result:'false',msg:'{0}'", ex.Message) + "}";
            }
        
        }

        //*******************************************
        //功能概要       ：添加查看房源业主信息的记录
        //参数説明       ：
        //返回值説明     ：
        //功能詳細       ：添加查看房源业主信息的记录
        //作成者         ：姚志强
        //作成日         ：2010-03-01
        //修改者         ：
        //修改日         ：
        //*******************************************
        public static string AddViewOwnerInfo(Chenxin.Lib.House.Entity.House_ViewOwerInfo viewOwnerInfo)
        {
            try
            {
                //添加查看房源业主信息的记录
                Chenxin.Lib.House.BLL.House_ViewOwerInfo.AddHouseViewOwerInfo(viewOwnerInfo);

                return "{" + string.Format("result:'true',msg:'{0}'", viewOwnerInfo.RecordId) + "}";
            }
            catch (Exception ex)
            {
                return "{" + string.Format("result:'true',msg:'{0}'", ex.Message) + "}";
            }
        }       

        //*******************************************
        //功能概要       ：获取房源信息
        //参数説明       ：
        //返回值説明     ：
        //功能詳細       ：获取房源信息
        //作成者         ：姚志强
        //作成日         ：2010-03-05
        //修改者         ：
        //修改日         ：
        //*******************************************
        public static List<Chenxin.Lib.House.Entity.House_BaseInfo> GetHouseInfoList(string strWhere) {
            try
            {
                //检索房源信息
                return Chenxin.Lib.House.DAL.House_BaseInfo.GetListArray(strWhere);
            }
            catch (Exception ex) {
                throw ex;
            }
        }

        //*******************************************
        //功能概要       ：获取房源实体对象
        //参数説明       ：
        //返回值説明     ：
        //功能詳細       ：获取房源实体对象
        //作成者         ：姚志强
        //作成日         ：2010-03-05
        //修改者         ：
        //修改日         ：
        //*******************************************
        public static Chenxin.Lib.House.Entity.House_BaseInfo GetHouseInfoEntity(string houseId)
        {
            //根据ID检索房源信息
            return Chenxin.Lib.House.DAL.House_BaseInfo.GetModel(new Guid(houseId));
        }

        //*******************************************
        //功能概要       ：获取房源实体对象
        //参数説明       ：
        //返回值説明     ：
        //功能詳細       ：获取房源实体对象
        //作成者         ：姚志强
        //作成日         ：2010-03-05
        //修改者         ：
        //修改日         ：
        //*******************************************
        public static Chenxin.Lib.House.Entity.House_BaseInfo GetHouseInfoEntityByCode(string houseCode)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat(" HouseCode='{0}'",houseCode);
            string strWhere = sb.ToString();
            //根据ID检索房源信息
            return Chenxin.Lib.House.DAL.House_BaseInfo.GetModel(strWhere);
        }

        //*******************************************
        //功能概要       ：获取房源经纪人信息
        //参数説明       ：
        //返回值説明     ：
        //功能詳細       ：获取房源经纪人信息
        //作成者         ：姚志强
        //作成日         ：2010-03-05
        //修改者         ：
        //修改日         ：
        //*******************************************
        public static Chenxin.Lib.Passport.Entity.Hr_UserInfo GetAddPersonInfo(Guid userId)
        {
            try
            {
                //根据ID检索房源信息
                return Chenxin.Lib.Passport.DAL.Hr_UserInfo.GetEntityById(userId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        //*******************************************
        //功能概要       ：获取查看过房源业主的人的信息
        //参数説明       ：
        //返回值説明     ：
        //功能詳細       ：获取查看过房源业主的人的信息
        //作成者         ：姚志强
        //作成日         ：2010-03-05
        //修改者         ：
        //修改日         ：
        //*******************************************
        public static List<Chenxin.Lib.House.Entity.House_ViewOwerInfo> GetViewOwnerInfo(string houseId)
        {
            try
            {
                string strWhere = string.Format("HouseId = '{0}'", new Guid(houseId));

                //根据ID检索房源信息
                return Chenxin.Lib.House.DAL.House_ViewOwerInfo.GetListArray(strWhere, "Addtime", "DESC");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        //*******************************************
        //功能概要       ：验证房源信息是否存在
        //参数説明       ：
        //返回值説明     ：
        //功能詳細       ：验证房源信息是否存在
        //作成者         ：姚志强
        //作成日         ：2010-03-01
        //修改者         ：
        //修改日         ：
        //*******************************************
        public static Boolean ValidateHouseKey(string communityId, string buildingId, string room) {

            string strWhere = string.Format("CommunityId = '{0}' AND BuildingId = '{1}' And Status >-10 ", new Guid(communityId), new Guid(buildingId));
            if (room != null && room.Trim() != "")
            {
                strWhere += string.Format(" AND Room = '{0}'", room);
            }

            List<Chenxin.Lib.House.Entity.House_BaseInfo> dicList = Chenxin.Lib.House.DAL.House_BaseInfo.GetListArray(strWhere);

            if (dicList != null && dicList.Count > 0)
            {
                return false;
            }
            else {
                return true;
            }
            
        }

        //*******************************************
        //功能概要       ：验证小区是否存在
        //参数説明       ：
        //返回值説明     ：
        //功能詳細       ：验证小区是否存在
        //作成者         ：姚志强
        //作成日         ：2010-03-01
        //修改者         ：
        //修改日         ：
        //*******************************************
        public static Boolean ValidateIsExistCommunity(string communityId, string communityName)
        {

            string strWhere = string.Format("communityName = '{0}' ", communityName);

            if (!string.IsNullOrEmpty(communityId)) {
                strWhere += string.Format(" AND communityId = '{0}' ", new Guid(communityId));
            }

            List<Chenxin.Lib.House.Entity.Community_BaseInfo> dicList = Chenxin.Lib.House.DAL.Community_BaseInfo.GetListArray(strWhere);

            if (dicList != null && dicList.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }

        }

        //*******************************************
        //功能概要       ：验证收藏中是否存在
        //参数説明       ：
        //返回值説明     ：
        //功能詳細       ：验证收藏中是否存在
        //作成者         ：姚志强
        //作成日         ：2010-03-01
        //修改者         ：
        //修改日         ：
        //*******************************************
        public static Boolean ValidateIsExistFavors(string favorsId,string userid)
        {

            string strWhere = string.Format("FavorId = '{0}' and FavorPersonId='{1}' ", favorsId,userid);

            List<Chenxin.Lib.House.Entity.Personal_FavorsInfo> dicList = Chenxin.Lib.House.DAL.Personal_FavorsInfo.GetListArray(strWhere, "FavorId");

            if (dicList != null && dicList.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }

        }

        //*******************************************
        //功能概要       ：通过客户ID获取房源ID
        //参数説明       ：CustomerId 客户ID
        //返回值説明     ：房源ID
        //功能詳細       ：通过客户ID获取房源ID
        //作成者         ：he.jifeng 
        //作成日         ：2010-07-30
        //修改者         ：
        //修改日         ：
        //*******************************************
        public static string GetHouseIdByCustomerId(string CustomerId)
        {
            string strRet = string.Empty;
            string strWhere = string.Format("CustomerId='{0}'", CustomerId);

            List<Chenxin.Lib.House.Entity.House_BaseInfo> lsHouseInfo =  Chenxin.Lib.House.DAL.House_BaseInfo.GetListArray(strWhere);

            if (lsHouseInfo.Count > 0)
            {
                strRet = lsHouseInfo[0].HouseId.ToString();
            }
            return strRet;
        }

        //*******************************************
        //功能概要       ：根据当前节点类型获取房源
        //参数説明       ：
        //返回值説明     ：
        //功能詳細       ：根据当前节点类型获取房源
        //作成者         ：何基锋
        //作成日         ：2010-08-11
        //*******************************************
        public static DataSet GetHouseListByParams(Dictionary<string, string> dicParams)
        {
            DataSet ds = null;

            int PageIndex = 1;
            int PageSize = 10;

            string OrderField = " House_BaseInfo.Adddate DESC";
            string TableName = "House_BaseInfo";
            StringBuilder strWhere = new StringBuilder();

            string FieldList = "Cur_Floor,Model_Toilet,Model_Room,Model_Hall,SalePrice_U, " +
                               "Status, Region, Community,BuildingName, Room, BusinessKind," +
                               "BuildingArea, SalePrice_T, RentPrice, OprDepart, OprPerson, ServiceTime,Adddate,Floor,Address,HouseStyle";

            string TableFieldList = "Cur_Floor,Total_Floor,Model_Toilet,Model_Room,Model_Hall,SalePrice_U, " +
                                    "CASE Status WHEN '10' THEN '有效' WHEN '-1' THEN '无效' WHEN '30' THEN '封盘' ELSE '暂缓' END AS Status," +
                                    "Region, Community,CASE BusinessKind WHEN '20' THEN '出租' WHEN '10' THEN '出售' ELSE '租售' END AS BusinessKind," +
                                    "BuildingName, Room, BuildingArea, SalePrice_T, floor(RentPrice) as RentPrice ,OprDepart, OprPerson, ServiceTime,Adddate," +
                                    "(CASE WHEN Cur_Floor IS NULL THEN '-' ELSE CAST(Cur_Floor AS VARCHAR(5)) END) + '/' +(CASE WHEN Total_Floor IS NULL THEN '-' ELSE CAST(Total_Floor AS VARCHAR(5)) END) AS Floor, " +
                                    "(Community + BuildingName + Room) AS Address," +
                                    "(CASE WHEN Model_Room IS NULL THEN '-' ELSE CAST(Model_Room AS VARCHAR(5)) END) + '/' + (CASE WHEN Model_Hall IS NULL THEN '-' ELSE CAST(Model_Hall AS VARCHAR(5)) END) + '/' + (CASE WHEN Model_Toilet IS NULL THEN '-' ELSE CAST(Model_Toilet AS VARCHAR(5)) END) AS HouseStyle ";

            if (dicParams.ContainsKey("sort"))
            {
                OrderField = dicParams["sort"];
            }

            strWhere.Append(" [Status]>-10 ");

            if (dicParams.ContainsKey("PageIndex"))
            {
                PageIndex = Convert.ToInt32(dicParams["PageIndex"]);
             }
            if (dicParams.ContainsKey("PageSize"))
            {
                PageSize = Convert.ToInt32(dicParams["PageSize"]);
            }

            if (dicParams.ContainsKey("StartDate"))
            {
                strWhere.AppendFormat(" AND Adddate >= '{0}'", dicParams["StartDate"]);
            }

            if (dicParams.ContainsKey("EndDate"))
            {
                strWhere.AppendFormat(" AND Adddate <= '{0}'", dicParams["EndDate"]);
            }

            if (dicParams.ContainsKey("dtype"))
            {
                string HouseType = dicParams["dtype"];
                if (HouseType.Equals("house_sale"))
                {
                    strWhere.AppendFormat(" AND (BusinessKind = {0} OR BusinessKind = {1})", 10, 30);
                }
                else if (HouseType.Equals("house_rent"))
                {
                    strWhere.AppendFormat(" AND BusinessKind = {0}", 20);
                }
            }

            if (dicParams.ContainsKey("ParentType"))
            {
                string ParentType = dicParams["ParentType"];
                switch (ParentType)
                {
                    case "0":
                        strWhere.AppendFormat("AND CityId='{0}'", dicParams["ParentId"]);
                        break;
                    case "10":
                        strWhere.AppendFormat("AND CompanyId='{0}'", dicParams["ParentId"]);
                        break;
                    case "20":
                        strWhere.Append("AND EXISTS(");
                        strWhere.Append("       SELECT 1");
                        strWhere.Append("       FROM Chenxin_Main.dbo.Hr_Struct_DepartTreeRelation R");
                        strWhere.Append("       WHERE OprDepartId = R.ChildId");
                        strWhere.AppendFormat(" AND ParentId='{0}'", dicParams["ParentId"]);
                        strWhere.Append("   )");
                        break;
                    case "25":
                    case "30":
                        strWhere.AppendFormat("AND OprDepartId='{0}'", dicParams["ParentId"]);
                        break;
                    case "40":
                        strWhere.AppendFormat("AND OprPersonId='{0}'", dicParams["ParentId"]);
                        break;
                    default:
                        break;
                }
            }

            ds = Chenxin.Lib.House.DAL.House_BaseInfo.GetList(PageIndex, PageSize, OrderField, TableName, strWhere.ToString(), FieldList, TableFieldList, true);
            return ds;
        }
        # endregion 公有方法

        # region 私有方法

        /// <summary>
        /// 获取房源
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        private static string GetHouseCode(Guid userId) {

            Database db = DatabaseFactory.CreateDatabase("Chenxin_House");
            DbCommand dbCommand = db.GetStoredProcCommand("usp_AutoGenerateHouseCode");

            //System.Data.SqlClient.SqlParameter 
            db.AddInParameter(dbCommand, "UserId", DbType.Guid, userId);
            db.AddOutParameter(dbCommand, "HouseCode", DbType.AnsiString, 150);
            db.ExecuteNonQuery(dbCommand);

            return db.GetParameterValue(dbCommand, "HouseCode").ToString();
            //return Convert.ToString(db.ExecuteDataSet(dbCommand).Tables[0].Rows[0].ItemArray[0]);
        }

        ///// <summary>
        ///// 插入系统操作日志
        ///// </summary>
        ///// <param name="houseBaseInfo"></param>
        ///// <param name="oprType"></param>
        ///// <param name="oprContext"></param>
        //private static void AddHouseUserLogs(Chenxin.Lib.House.Entity.House_BaseInfo houseBaseInfo, string oprType, string oprContext)
        //{
        //    //添加日志
        //    Chenxin.Lib.House.Entity.House_UserLogs userLogs = new Chenxin.Lib.House.Entity.House_UserLogs();

        //    userLogs.RecordId = Guid.NewGuid();
        //    userLogs.UserId = houseBaseInfo.OprPersonId;
        //    userLogs.UserName = houseBaseInfo.OprPerson;
        //    userLogs.DepartId = houseBaseInfo.OprDepartId;
        //    userLogs.DepartName = houseBaseInfo.OprDepart;
        //    userLogs.OprType = oprType;
        //    userLogs.OperationContext = oprContext;
        //    userLogs.Addtime = DateTime.Now;
        //    //****************修改开始***********************************
        //    userLogs.Id = houseBaseInfo.HouseId;
        //    //****************修改结束***********************************
        //    Chenxin.Lib.House.BLL.House_UserLogs.AddHouseUserLogs(userLogs);

        //}

        #region 写入房源更改记录 该方法已经有新方法替代，弃用 熊世宏 2010-04-29

        //*******************************************
        //功能概要       ：写入房源更改记录
        //参数説明       ：
        //返回值説明     ：
        //功能詳細       ：写入房源更改记录
        //作成者         ：姚志强
        //作成日         ：2010-03-01
        //修改者         ：
        //修改日         ：
        //*******************************************
        private static String AddHouseInfoBak(Chenxin.Lib.House.Entity.House_BaseInfo houseBaseInfo, Chenxin.Lib.House.Entity.House_BaseInfo oldHouseInfo)
        {
            StringBuilder updateContext = new StringBuilder();

            //判断区域是否被修改
            if (!strEqual(houseBaseInfo.Region, oldHouseInfo.Region))
            {
                updateContext.Append(AddHouseInfoBakCol(houseBaseInfo, "Region", "区域", oldHouseInfo.Region, houseBaseInfo.Region));
            }

            //判断板块是否被修改
            if (!strEqual(houseBaseInfo.Block, oldHouseInfo.Block))
            {
                updateContext.Append(AddHouseInfoBakCol(houseBaseInfo, "Block", "板块", oldHouseInfo.Block, houseBaseInfo.Block));
            }

            //判断交易类型是否被修改
            if (houseBaseInfo.BusinessKind != oldHouseInfo.BusinessKind)
            {
                string oldBusinessValue = "";
                string newBusinessValue = "";

                if (houseBaseInfo.BusinessKind == 10)
                    newBusinessValue = "出售";
                else if (houseBaseInfo.BusinessKind == 20)
                    newBusinessValue = "出租";
                else
                    newBusinessValue = "租售";

                if (oldHouseInfo.BusinessKind == 10)
                    oldBusinessValue = "出售";
                else if (oldHouseInfo.BusinessKind == 20)
                    oldBusinessValue = "出租";
                else
                    oldBusinessValue = "租售";

                updateContext.Append(AddHouseInfoBakCol(houseBaseInfo, "BusinessKind", "交易类型", oldBusinessValue, newBusinessValue));
            }

            //判断状态是否被修改
            if (houseBaseInfo.Status != oldHouseInfo.Status)
            {
                string oldStatus = "";
                string newStatus = "";

                if (houseBaseInfo.Status == 10)
                    newStatus = "有效";
                else if (houseBaseInfo.Status == -10)
                    newStatus = "无效";
                else
                    newStatus = "暂缓";

                if (oldHouseInfo.Status == 10)
                    oldStatus = "有效";
                else if (oldHouseInfo.Status == -10)
                    oldStatus = "无效";
                else
                    oldStatus = "暂缓";

                updateContext.Append(AddHouseInfoBakCol(houseBaseInfo, "Status", "状态", oldStatus, newStatus));
            }

            //判断用途是否被修改
            if (!strEqual(houseBaseInfo.HouseUse, oldHouseInfo.HouseUse))
            {
                updateContext.Append(AddHouseInfoBakCol(houseBaseInfo, "HouseUse", "用途", oldHouseInfo.HouseUse, houseBaseInfo.HouseUse));
            }

            //判断类型是否被修改
            if (!strEqual(houseBaseInfo.BuildingType, oldHouseInfo.BuildingType))
            {
                updateContext.Append(AddHouseInfoBakCol(houseBaseInfo, "BuildingType", "类型", oldHouseInfo.BuildingType, houseBaseInfo.BuildingType));
            }

            //判断出售总价是否被修改
            if (houseBaseInfo.SalePrice_T != oldHouseInfo.SalePrice_T)
            {
                updateContext.Append(AddHouseInfoBakCol(houseBaseInfo, "SalePrice_T", "出售总价", Convert.ToString(oldHouseInfo.SalePrice_T), Convert.ToString(houseBaseInfo.SalePrice_T)));
            }

            //判断出售底价是否被修改
            if (houseBaseInfo.SalePrice_R != oldHouseInfo.SalePrice_R)
            {
                updateContext.Append(AddHouseInfoBakCol(houseBaseInfo, "SalePrice_R", "出售底价", Convert.ToString(oldHouseInfo.SalePrice_R), Convert.ToString(houseBaseInfo.SalePrice_R)));
            }

            //判断出租总价是否被修改
            if (houseBaseInfo.RentPrice != oldHouseInfo.RentPrice)
            {
                updateContext.Append(AddHouseInfoBakCol(houseBaseInfo, "RentPrice", "出租总价", Convert.ToString(oldHouseInfo.RentPrice), Convert.ToString(houseBaseInfo.RentPrice)));
            }

            //判断出租底价是否被修改
            if (houseBaseInfo.RentPrice_R != oldHouseInfo.RentPrice_R)
            {
                updateContext.Append(AddHouseInfoBakCol(houseBaseInfo, "RentPrice_R", "出租底价", Convert.ToString(oldHouseInfo.RentPrice_R), Convert.ToString(houseBaseInfo.RentPrice_R)));
            }

            //判断建筑面积是否被修改
            if (houseBaseInfo.BuildingArea != oldHouseInfo.BuildingArea)
            {
                updateContext.Append(AddHouseInfoBakCol(houseBaseInfo, "BuildingArea", "建筑面积", Convert.ToString(oldHouseInfo.BuildingArea), Convert.ToString(houseBaseInfo.BuildingArea)));
            }

            //判断房型-室是否被修改
            if (houseBaseInfo.Model_Room != oldHouseInfo.Model_Room)
            {
                updateContext.Append(AddHouseInfoBakCol(houseBaseInfo, "Model_Room", "房型-室", Convert.ToString(oldHouseInfo.Model_Room), Convert.ToString(houseBaseInfo.Model_Room)));
            }

            //判断房型-厅是否被修改
            if (houseBaseInfo.Model_Hall != oldHouseInfo.Model_Hall)
            {
                updateContext.Append(AddHouseInfoBakCol(houseBaseInfo, "Model_Hall", "房型-厅", Convert.ToString(oldHouseInfo.Model_Hall), Convert.ToString(houseBaseInfo.Model_Hall)));
            }

            //判断房型-卫是否被修改
            if (houseBaseInfo.Model_Toilet != oldHouseInfo.Model_Toilet)
            {
                updateContext.Append(AddHouseInfoBakCol(houseBaseInfo, "Model_Toilet", "房型-卫", Convert.ToString(oldHouseInfo.Model_Toilet), Convert.ToString(houseBaseInfo.Model_Toilet)));
            }

            //判断房型-阳台是否被修改
            if (houseBaseInfo.Model_Balcony != oldHouseInfo.Model_Balcony)
            {
                updateContext.Append(AddHouseInfoBakCol(houseBaseInfo, "Model_Balcony", "房型-阳台", Convert.ToString(oldHouseInfo.Model_Balcony), Convert.ToString(houseBaseInfo.Model_Balcony)));
            }

            //判断所在楼层是否被修改
            if (houseBaseInfo.Cur_Floor != oldHouseInfo.Cur_Floor)
            {
                updateContext.Append(AddHouseInfoBakCol(houseBaseInfo, "Cur_Floor", "所在楼层", Convert.ToString(oldHouseInfo.Cur_Floor), Convert.ToString(houseBaseInfo.Cur_Floor)));
            }

            //判断总楼层是否被修改
            if (houseBaseInfo.Total_Floor != oldHouseInfo.Total_Floor)
            {
                updateContext.Append(AddHouseInfoBakCol(houseBaseInfo, "Total_Floor", "总楼层", Convert.ToString(oldHouseInfo.Total_Floor), Convert.ToString(houseBaseInfo.Total_Floor)));
            }

            //判断现状是否被修改
            if (!strEqual(houseBaseInfo.Actuality, oldHouseInfo.Actuality))
            {
                updateContext.Append(AddHouseInfoBakCol(houseBaseInfo, "Actuality", "现状", oldHouseInfo.Actuality, houseBaseInfo.Actuality));
            }

            //判断产权情况是否被修改
            if (!strEqual(houseBaseInfo.Property, oldHouseInfo.Property))
            {
                updateContext.Append(AddHouseInfoBakCol(houseBaseInfo, "Property", "产权情况", oldHouseInfo.Property, houseBaseInfo.Property));
            }

            //判断竣工年份是否被修改
            if (houseBaseInfo.CompleteYear != oldHouseInfo.CompleteYear)
            {
                updateContext.Append(AddHouseInfoBakCol(houseBaseInfo, "CompleteYear", "竣工年份", Convert.ToString(oldHouseInfo.CompleteYear), Convert.ToString(houseBaseInfo.CompleteYear)));
            }

            //判断租约是否被修改
            if (houseBaseInfo.HavRentContract != oldHouseInfo.HavRentContract)
            {
                string oldHavRentContract = "";
                string newHavRentContract = "";

                if (houseBaseInfo.HavRentContract == true)
                    newHavRentContract = "有";
                else
                    newHavRentContract = "无";

                if (oldHouseInfo.HavRentContract == true)
                    oldHavRentContract = "有";
                else
                    oldHavRentContract = "无";

                updateContext.Append(AddHouseInfoBakCol(houseBaseInfo, "HavRentContract", "租约", oldHavRentContract, newHavRentContract));
            }

            //判断钥匙是否被修改
            if (houseBaseInfo.IsHavekey != oldHouseInfo.IsHavekey)
            {
                string oldIsHavekey = "";
                string newIsHavekey = "";

                if (houseBaseInfo.IsHavekey == true)
                    newIsHavekey = "有";
                else
                    newIsHavekey = "无";

                if (oldHouseInfo.IsHavekey == true)
                    oldIsHavekey = "有";
                else
                    oldIsHavekey = "无";

                updateContext.Append(AddHouseInfoBakCol(houseBaseInfo, "IsHavekey", "钥匙", oldIsHavekey, newIsHavekey));
            }

            //判断来源是否被修改
            if (!strEqual(houseBaseInfo.InfoSource, oldHouseInfo.InfoSource))
            {
                updateContext.Append(AddHouseInfoBakCol(houseBaseInfo, "InfoSource", "来源", oldHouseInfo.InfoSource, houseBaseInfo.InfoSource));
            }

            //判断房源配置是否被修改
            if (!strEqual(houseBaseInfo.BaseEquip, oldHouseInfo.BaseEquip))
            {
                updateContext.Append(AddHouseInfoBakCol(houseBaseInfo, "BaseEquip", "房源配置", oldHouseInfo.BaseEquip, houseBaseInfo.BaseEquip));
            }

            //判断备注是否被修改
            if (!strEqual(houseBaseInfo.Remarks, oldHouseInfo.Remarks))
            {
                updateContext.Append(AddHouseInfoBakCol(houseBaseInfo, "Remarks", "备注", oldHouseInfo.Remarks, houseBaseInfo.Remarks));
            }

            return updateContext.ToString();

        }

        #endregion

        #region 添加更该的字段信息 该方法已经弃用 熊世宏 2010-04-29

        //*******************************************
        //功能概要       ：添加更该的字段信息
        //参数説明       ：
        //返回值説明     ：
        //功能詳細       ：添加更该的字段信息
        //作成者         ：姚志强
        //作成日         ：2010-03-01
        //修改者         ：
        //修改日         ：
        //*******************************************
        private static String AddHouseInfoBakCol(Chenxin.Lib.House.Entity.House_BaseInfo houseBaseInfo, string colomuName, string colomuDesc, string oldValue, string newValue)
        {
            Chenxin.Lib.House.Entity.House_BaseInfo_BakCol houseBaseInfoBakCol = new Chenxin.Lib.House.Entity.House_BaseInfo_BakCol();
            string changeDesc = colomuDesc + "由:" + oldValue + " 修改为:" + newValue + " ";

            houseBaseInfoBakCol.RecordId = Guid.NewGuid();
            houseBaseInfoBakCol.HouseId = houseBaseInfo.HouseId;
            houseBaseInfoBakCol.ColumnName = colomuName;
            houseBaseInfoBakCol.ColumnDesc = colomuDesc;
            houseBaseInfoBakCol.OldValue = oldValue;
            houseBaseInfoBakCol.NewValue = newValue;
            houseBaseInfoBakCol.ChangeDesc = changeDesc;
            houseBaseInfoBakCol.OperatorId = houseBaseInfo.OprPersonId;
            houseBaseInfoBakCol.Operator = houseBaseInfo.OprPerson;
            houseBaseInfoBakCol.Adddate = DateTime.Now;

            //*********************chenYuGong 20100331 追加开始***********************
            houseBaseInfoBakCol.CompanyId = houseBaseInfo.CompanyId;
            houseBaseInfoBakCol.CompanyName = houseBaseInfo.CompanyName;
            //**********************chenYuGong 20100331 追加结束********************

            Chenxin.Lib.House.DAL.House_BaseInfo_BakCol.Add(houseBaseInfoBakCol);

            return changeDesc;
        }

        #endregion

        /// <summary>
        /// 添加房源修改跟单信息
        /// </summary>
        /// <param name="houseBaseInfo"></param>
        /// <param name="updateContext"></param>
        private static void AddTraceInfo(Chenxin.Lib.House.Entity.House_BaseInfo houseBaseInfo, string updateContext, Chenxin.Lib.House.Entity.House_TraceInfo traceInfo)
        {
            traceInfo.TraceId = Guid.NewGuid();
            traceInfo.TraceType = 0;
            traceInfo.TraceContext = updateContext;
            traceInfo.HouseId = houseBaseInfo.HouseId;
            traceInfo.HouseCode = houseBaseInfo.HouseCode;
            traceInfo.HouseAddress = houseBaseInfo.Address;
            traceInfo.TraceTime = DateTime.Now;
            traceInfo.status = 0;

            traceInfo.OprDepart = houseBaseInfo.OprDepart;
            traceInfo.OprDepartId = houseBaseInfo.OprDepartId;
            traceInfo.OprPerson = houseBaseInfo.OprPerson;
            traceInfo.OprPersonId = houseBaseInfo.OprPersonId;

            Chenxin.Lib.House.BLL.House_TraceInfo.AddHouseTraceInfo(traceInfo);
        }

        
        /// <summary>
        /// 添加房源修改
        /// </summary>
        /// <param name="houseBaseInfo"></param>
        /// <param name="noticeTitle"></param>
        /// <param name="noticeBody"></param>
        private static void AddNotice(Chenxin.Lib.House.Entity.House_BaseInfo houseBaseInfo, string noticeTitle, string noticeBody)
        {
            Chenxin.Lib.House.Entity.Notice notice = new Chenxin.Lib.House.Entity.Notice();

            notice.RecordId = Guid.NewGuid();
            notice.NoticeType = 0;
            //****************chenyugong 20100331 追加开始 **********************
            notice.CompanyId = houseBaseInfo.CompanyId;
            notice.CompanyName = houseBaseInfo.CompanyName;
            //****************chenyugong 20100331 追加结束**********************
            notice.Title = noticeTitle;
            notice.body = noticeBody;
            notice.SenderId = Guid.Empty;
            notice.DelFlg = 0;
            notice.DepartMentId = houseBaseInfo.OprDepartId;
            notice.SendDate = DateTime.Now;
            notice.UpdateDate = DateTime.Now;
            notice.CityId = houseBaseInfo.CityId;
            notice.ReadFlg = 0;

            Chenxin.Lib.House.BLL.Notice.AddNotice(notice);

        } 

        //*******************************************
        //功能概要       ：比较字符串是否相等
        //参数説明       ：
        //返回值説明     ：
        //功能詳細       ：比较字符串是否相等
        //作成者         ：姚志强
        //作成日         ：2010-03-01
        //修改者         ：
        //修改日         ：
        //*******************************************
        private static bool strEqual(string str1, string str2)
        {
            if (str1 == null) {
                str1 = "";
            }

            if (str2 == null) {
                str2 = "";
            }

            return str1.Equals(str2);
        }
       
        #endregion 私有方法
    }
}
